package com.mldong.modules.sys.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mldong.base.CommonPage;
import com.mldong.base.YesNoEnum;
import com.mldong.modules.sys.dto.TaskExecutionHistoryPageParam;
import com.mldong.modules.sys.dto.TaskExecutionHistoryParam;
import com.mldong.modules.sys.vo.TaskExecutionHistoryVO;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import com.mldong.util.LowCodeServiceUtil;
import com.mldong.modules.sys.entity.TaskExecutionHistory;
import com.mldong.modules.sys.mapper.TaskExecutionHistoryMapper;
import com.mldong.modules.sys.service.TaskExecutionHistoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
 * <p>
 * 已完成任务的历史归档 服务实现类
 * </p>
 *
 * @author mldong
 * @since 2025-10-12
 */
@Service
public class TaskExecutionHistoryServiceImpl extends ServiceImpl<TaskExecutionHistoryMapper, TaskExecutionHistory> implements TaskExecutionHistoryService {
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(TaskExecutionHistoryParam param) {
        param.setId(null);
        TaskExecutionHistory taskExecutionHistory = new TaskExecutionHistory();
        BeanUtil.copyProperties(param, taskExecutionHistory);
        return super.save(taskExecutionHistory);
    }

    @Override
    public boolean update(TaskExecutionHistoryParam param) {
        TaskExecutionHistory taskExecutionHistory = new TaskExecutionHistory();
        BeanUtil.copyProperties(param, taskExecutionHistory);
        return LowCodeServiceUtil.updateById(baseMapper,taskExecutionHistory,TaskExecutionHistoryParam.class);
    }

    @Override
    public CommonPage<TaskExecutionHistoryVO> page(TaskExecutionHistoryPageParam param) {
        IPage<TaskExecutionHistoryVO> page = param.buildMpPage();
        QueryWrapper queryWrapper = param.buildQueryWrapper();
        List<TaskExecutionHistoryVO> list = baseMapper.selectCustom(page, queryWrapper);
        page.setRecords(list);
        return CommonPage.toPage(page);
    }
    @Override
    public TaskExecutionHistoryVO findById(Long id) {
        return baseMapper.findById(id);
    }
}
